<template>
	<a-config-provider
		:locale="zhCN"
		:theme="{
			token: {
				colorPrimary: themeConfig.primary,
			}
		}"
		:component-size="globalSize"
	>
		<a-watermark :content="[themeConfig.watermarkText]">
			<router-view></router-view>
		</a-watermark>
	</a-config-provider>
</template>

<script setup lang="ts">
import {onBeforeMount,onMounted,nextTick,watch,computed} from 'vue'
import {apiSysConfigSysInfoGet} from '@/api/sys/sysConfig'
import { useThemeConfig } from './stores/themeConfig'
import {storeToRefs} from 'pinia'
import {Local,Session,useTitle} from '@/utils/index'
import {useTagsViewRoutes} from '@/stores/tagsViewRoutes'
import {useRoute} from 'vue-router'
import zhCN from 'ant-design-vue/es/locale/zh_CN';

const route = useRoute();

const stores = useTagsViewRoutes();
const storesThemeConfig = useThemeConfig()
const {themeConfig} = storeToRefs(storesThemeConfig)

console.log("当前环境",import.meta.env)

watch(
	()=>route.path,
	()=>{
		useTitle()
	},{
	deep:true,
})

const globalSize:any = computed(()=>{
    return themeConfig.value.globalComponentSize
})

onMounted(()=>{
	nextTick(()=>{
		// 获取缓存中的布局配置
			if (Local.get('themeConfig')) {
				storesThemeConfig.setThemeConfig({ themeConfig: Local.get('themeConfig') });
			}
			// 获取缓存中的全屏配置
			if (Session.get('isTagsViewCurrenFull')) {
				stores.setCurrenFullscreen(Session.get('isTagsViewCurrenFull'));
			}
	})
})

onBeforeMount(async ()=>{
	const res = await apiSysConfigSysInfoGet()
	if (res.data.type != 'success') return;
	const data = res.data.result;
	// 系统logo
	themeConfig.value.logoUrl = data.logo;
	// 主标题
	themeConfig.value.globalTitle = data.title;
	// 副标题
	themeConfig.value.globalViceTitle = data.viceTitle;
	// 系统说明
	themeConfig.value.globalViceTitleMsg = data.viceDesc;
	// Icp备案信息
	themeConfig.value.icp = data.icp;
	themeConfig.value.icpUrl = data.icpUrl;
	// 水印
	themeConfig.value.isWatermark = data.watermark != null;
	themeConfig.value.watermarkText = data.watermark;
	// 版权说明
	themeConfig.value.copyright = data.copyright;
	// 登录验证
	themeConfig.value.secondVer = data.secondVer == 1;
	themeConfig.value.captcha = data.captcha == 1;
	// 登陆时隐藏租户
	themeConfig.value.hideTenantForLogin = data.hideTenantForLogin;
	// 注册功能
	themeConfig.value.registration = data.enableReg == 1;
	// 更新配置加载状态
	themeConfig.value.isLoaded = true;
	Local.remove('themeConfig');
	Local.set('themeConfig', storesThemeConfig.themeConfig);
})
</script>

<style lang="scss" scoped>

</style> 